package com.yc.bbs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yc.bbs.entity.User;
import com.yc.bbs.dao.UserMapper;
import com.yc.bbs.service.BizException;
import com.yc.bbs.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * BBS论坛-用户表-6 服务实现类
 * </p>
 *
 * @author ly
 * @since 2024-11-23
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User login(User user) throws BizException {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getUname, user.getUname());
        lqw.eq(User::getUpass, user.getUpass());
        User dbUser = userMapper.selectOne(lqw);
        if(dbUser == null){
            throw new BizException("用户名或密码错误!", null);
        }
        return dbUser;
    }
}
